﻿using System;
using System.Linq;

namespace ECommerce.Controls
{
	public partial class RightAd : BaseUserControl
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{
				BuildToysLink();
			}
		}

		private void BuildToysLink()
		{
			if (SiteContext.Current != null && SiteContext.Current.WorkingLanguage != null)
			{
				var categoryService = new Service.CategoryService();

				var languageID = SiteContext.Current.WorkingLanguage.LanguageId;

				var categoryByLang = categoryService.GetCategoryByLanguage(languageID);

				if (categoryByLang != null)
				{
					var theToysCategory = categoryByLang.Where(exp => exp.CategoryName.Contains("玩具") || exp.CategoryName.Contains("toy")).FirstOrDefault();

					if (theToysCategory != null)
					{
						HyperLinkToys.NavigateUrl = "~/Category.aspx?categoryid=" + theToysCategory.CategoryID.ToString();
					}
					else
					{
						HyperLinkToys.NavigateUrl = "~/Category.aspx";
					}
				}
			}
			else
			{
				HyperLinkToys.NavigateUrl = "#";
			}
		}
	}
}